<template>
  <teleport to="#loading">
    <div :style="{ backgroundColor : backgroundColor || '' }" class="d-flex justify-content-center align-items-center h-100 loading-container">
      <div class="loading-content">
        <div class="spinner-border text-primary">
          <span class="visually-hidden">{{ text || 'Loading...' }}</span>
        </div>
        <p v-if="text" class="text-primary small">{{ text }}</p>
      </div>
    </div>
  </teleport>
</template>

<script lang='ts'>
import { defineComponent } from 'vue'
import useDOMCreate from '../hooks/useDOMCreate'

export default defineComponent({
  props: {
    text: {
      type: String
    },
    backgroundColor: {
      type: String
    }
  },
  setup () {
    useDOMCreate('loading')
  }
})
</script>

<style>
  .loading-container{
    background: rgba(255, 255, 255, .5);
    z-index: 100;
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    text-align: center;
  }
</style>
